package com.cdivtc.management.utils;

import org.springframework.stereotype.Component;

import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;



public class getMD5file {
    public static String getMD5Str(InputStream file) {

        InputStream in = null;
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            in = file;
            byte[]bs = new byte[1024];
            int len = -1;
            while((len=in.read(bs))!=-1) {
                digest.update(bs,0,len);
            }
            BigInteger bi = new BigInteger(1,digest.digest());
            return bi.toString(16);
        } catch (NoSuchAlgorithmException e) {
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}
